/*
 * @Author: 梁青春
 * @Date: 2025-02-20 10:56:40
 * @LastEditTime: 2025-02-24 09:58:35
 * @LastEditors: 梁青春
 */
import './assets/styles/main.scss'
import 'element-plus/theme-chalk/dark/css-vars.css'
import './assets/styles/el.dark.style.scss'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import * as VueRouter from 'vue-router'
import routes from './router'
import App from './App.vue'

import { parseTime } from '@/utils/ruoyi'
import { getConfigKey } from '@/api/system/config'

let app = null
let router = null
let history = null
// 👇 将渲染操作放入 mount 函数，子应用初始化时会自动执行
window.mount = () => {
    history = VueRouter.createWebHistory()
    router = VueRouter.createRouter({
        history,
        routes,
    })

    app = createApp(App)
    app.use(createPinia())
    app.use(router)

    app.config.globalProperties.getConfigKey = getConfigKey
    app.config.globalProperties.parseTime = parseTime

    app.mount('#my-screen-app')
}

// 👇 将卸载操作放入 unmount 函数，就是上面步骤2中的卸载函数
window.unmount = () => {
    app.unmount()
    history.destroy()
    app = null
    router = null
    history = null
}

// 如果不在微前端环境，则直接执行mount渲染
if (!window.__MICRO_APP_ENVIRONMENT__) {
    window.mount()
}